<template>
  <div>
    <a-card class="card" title="新人黑马排行榜" :bordered="false">
      <a-table
        :columns="columns"
        :dataSource="userList"
        :rowKey="userList => userList.jds_user_id"
        :pagination="false"
        :loading="loading"
      >
        <div slot="rate" slot-scope="row">
          <a-progress :percent="parseInt(row.rate)" size="small" status="active" />
        </div>
      </a-table>
    </a-card>
    <br />
  </div>
</template>

<script>
import { getDarkList } from '@/api/user/darkhorse'
const columns = [
  {
    title: '序号',
    customRender: (text, row, index) => {
      return index + 1
    }
  },
  {
    title: '目标业绩',
    dataIndex: 'perGoals'
  },
  {
    title: '姓名',
    dataIndex: 'user'
  },
  {
    title: '入职时间',
    dataIndex: 'useTime'
  },
  {
    title: '前天',
    dataIndex: 'listday',
    sorter: (a, b) => a.listday - b.listday
  },
  {
    title: '昨天',
    dataIndex: 'yestoday',
    sorter: (a, b) => a.yestoday - b.yestoday
  },
  {
    title: '今天',
    dataIndex: 'today',
    sorter: (a, b) => a.today - b.today
  },
  {
    title: '今天增长',
    dataIndex: 'todayUp',
    sorter: (a, b) => a.todayUp - b.todayUp

  },
  {
    title: '昨天增长',
    dataIndex: 'yestodayUp',
    sorter: (a, b) => a.yestodayUp - b.yestodayUp
  },
  {
    title: '两天比较',
    dataIndex: 'twoUp',
    sorter: (a, b) => a.twoUp - b.twoUp
  },
  {
    title: '本月总计',
    dataIndex: 'month',
    sorter: (a, b) => a.month - b.month
  },
  {
    title: '所属小组',
    dataIndex: 'groupName'
  },
  {
    title: '目标完成率',
    scopedSlots: { customRender: 'rate' }
  }
]

const userList = [
  // {
  //   jds_user_id: 1,
  //   perGoals: 1000,
  //   user: '张三',
  //   useTime: '2020-4-6',
  //   day1: 20,
  //   day2: 30,
  //   day3: 10,
  //   month: 1205,
  //   groupName: '哈哈',
  //   rate: 70
  // }
]

export default {
  name: 'Ranking',
  data () {
    return {
    //   description: '黑马业绩排行榜单。',
      columns,
      userList,
      loading: false
    }
  },
  created () {
    this.getDarkList()
  },
  methods: {
    getDarkList () {
      this.loading = true
      this.grouploading = true
      getDarkList({})
        .then(res => {
          this.userList = res.result
          this.loading = false
        })
        .catch(err => {
          this.loading = false
          console.log(err)
        })
    }
  },
  filters: {
    numFilter (value) {
      let realVal = ''
      if (!isNaN(value) && value !== '') {
        // 截取当前数据到小数点后两位
        realVal = parseFloat(value).toFixed(2)
      } else {
        realVal = '--'
      }
      return realVal
    }
  }
}
</script>
